package com.example.ftpfilesync.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@ConfigurationProperties(prefix = "file-sync")
public class FtpProperties {

    // 全局配置
    private long checkInterval = 5000; // 检查间隔，单位毫秒
    private boolean detectModifiedFiles = true; // 是否检测已同步文件的修改并重新同步，默认开启
    private boolean preserveTimestamps = true; // 是否保持文件的时间戳一致，默认开启
    
    // 多线程配置
    private boolean enableMultiThread = false; // 是否启用多线程同步
    private int maxThreads = 5; // 最大线程数
    private int batchThreshold = 10; // 批量处理阈值
    private long largeFileThreshold = 10485760L; // 大文件阈值（10MB）
    
    // 多任务配置
    private List<SyncTask> syncTasks = new ArrayList<>();
    
    // 全局FTP配置
    private Ftp ftp = new Ftp();
    
    public static class Ftp {
        private String host;
        private int port = 21;
        private String username;
        private String password;

        // 必须提供无参构造函数
        public Ftp() {}

        public String getHost() {
            return host;
        }

        public void setHost(String host) {
            this.host = host;
        }

        public int getPort() {
            return port;
        }

        public void setPort(int port) {
            this.port = port;
        }

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }
    }
    
    // 同步任务配置类
    public static class SyncTask {
        private String name; // 任务名称
        private boolean enabled = true; // 是否启用
        private String sourcePath; // 源目录
        private boolean useFtp = true; // 是否使用FTP
        private String targetPath; // FTP目标目录
        private String localTargetPath; // 本地目标目录
        private Boolean detectModifiedFiles; // 是否检测已同步文件的修改（可覆盖全局配置）
        private Boolean preserveTimestamps; // 是否保持文件的时间戳一致（可覆盖全局配置）
        private Long largeFileThreshold; // 大文件阈值（可覆盖全局配置）
        
        // FTP配置
        private Ftp ftp;
        
        // 必须提供无参构造函数
        public SyncTask() {}
        
        // Getters and Setters
        public String getName() {
            return name;
        }
        
        public void setName(String name) {
            this.name = name;
        }
        
        public boolean isEnabled() {
            return enabled;
        }
        
        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
        
        public String getSourcePath() {
            return sourcePath;
        }
        
        public void setSourcePath(String sourcePath) {
            this.sourcePath = sourcePath;
        }
        
        public boolean isUseFtp() {
            return useFtp;
        }
        
        public void setUseFtp(boolean useFtp) {
            this.useFtp = useFtp;
        }
        
        public String getTargetPath() {
            return targetPath;
        }
        
        public void setTargetPath(String targetPath) {
            this.targetPath = targetPath;
        }
        
        public String getLocalTargetPath() {
            return localTargetPath;
        }
        
        public void setLocalTargetPath(String localTargetPath) {
            this.localTargetPath = localTargetPath;
        }
        
        public Boolean getDetectModifiedFiles() {
            return detectModifiedFiles;
        }
        
        public void setDetectModifiedFiles(Boolean detectModifiedFiles) {
            this.detectModifiedFiles = detectModifiedFiles;
        }
        
        public Boolean getPreserveTimestamps() {
            return preserveTimestamps;
        }
        
        public void setPreserveTimestamps(Boolean preserveTimestamps) {
            this.preserveTimestamps = preserveTimestamps;
        }
        
        public Long getLargeFileThreshold() {
            return largeFileThreshold;
        }
        
        public void setLargeFileThreshold(Long largeFileThreshold) {
            this.largeFileThreshold = largeFileThreshold;
        }
        
        public Ftp getFtp() {
            return ftp;
        }
        
        public void setFtp(Ftp ftp) {
            this.ftp = ftp;
        }
    }

    // Getters and Setters
    public long getCheckInterval() {
        return checkInterval;
    }

    public void setCheckInterval(long checkInterval) {
        this.checkInterval = checkInterval;
    }

    public boolean isDetectModifiedFiles() {
        return detectModifiedFiles;
    }

    public void setDetectModifiedFiles(boolean detectModifiedFiles) {
        this.detectModifiedFiles = detectModifiedFiles;
    }

    public boolean isPreserveTimestamps() {
        return preserveTimestamps;
    }

    public void setPreserveTimestamps(boolean preserveTimestamps) {
        this.preserveTimestamps = preserveTimestamps;
    }

    public boolean isEnableMultiThread() {
        return enableMultiThread;
    }

    public void setEnableMultiThread(boolean enableMultiThread) {
        this.enableMultiThread = enableMultiThread;
    }

    public int getMaxThreads() {
        return maxThreads;
    }

    public void setMaxThreads(int maxThreads) {
        this.maxThreads = maxThreads;
    }

    public int getBatchThreshold() {
        return batchThreshold;
    }

    public void setBatchThreshold(int batchThreshold) {
        this.batchThreshold = batchThreshold;
    }

    public long getLargeFileThreshold() {
        return largeFileThreshold;
    }

    public void setLargeFileThreshold(long largeFileThreshold) {
        this.largeFileThreshold = largeFileThreshold;
    }

    public List<SyncTask> getSyncTasks() {
        return syncTasks;
    }

    public void setSyncTasks(List<SyncTask> syncTasks) {
        this.syncTasks = syncTasks;
    }
    
    public Ftp getFtp() {
        return ftp;
    }
    
    public void setFtp(Ftp ftp) {
        this.ftp = ftp;
    }
}